package cst.a330gjq.startproject_330gjq;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import cst.a330gjq.startproject_330gjq.bean.WeatherInfo;
import cst.a330gjq.startproject_330gjq.listener.WeatherListener;
import cst.a330gjq.startproject_330gjq.model.Weather51Model;

public class MainActivity extends AppCompatActivity {
    private EditText city_edit;//类型是编辑文本
    private Button btn_1;
    private TextView city_text;
    private TextView wd_text;
    private TextView WD_text;
    private TextView WS_text;
    private Weather51Model model;
    private WeatherListener listener;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        city_edit = (EditText) findViewById(R.id.city_edit);
        //(EditText)类型转换
        btn_1 = (Button) findViewById(R.id.btn_1);
        city_text = (TextView) findViewById(R.id.city_text);
        wd_text = (TextView) findViewById(R.id.wd_text);
        WD_text = (TextView) findViewById(R.id.WD_text);
        WS_text = (TextView) findViewById(R.id.WS_text);
        listener = new WeatherListener() {
            @Override
            public void onResponse(WeatherInfo w) {
                city_text.setText(w.getCity());
                wd_text.setText(w.getTemp());
            }

            @Override
            public void onFail(String msg) {
                city_text.setText("解析错误");

            }
        };

        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                model = new Weather51Model();
                model.getWeather(city_edit.getText().toString(),
                        listener);
            }
        });

    }

}
